<% include "/WEB-INF/includes/cabeceira.gtpl" %>

<div id="content" class="group">

<%
/*def sesion = request.getSession(true)
def usuario = sesion.usuario*/
def erro = request.getAttribute('erro') 
def mensaxeExito = request.getAttribute('mensaxe')
%>

<% if (erro) { %>
<div class="erro">
${erro?:''}
</div>
<% } %>

<% if (mensaxeExito) { %>
<div class="exito">
${mensaxeExito?:''}
</div>
<% } %>


<div id="container">
<div id="container-inner">

<h1>engade un sitio de interese</h1>

<form id="formulario" method="POST" action="crea/sitio">
       
       
<fieldset>
<p></p>

<div class="campo">
<label class="etiqueta" for="sitio">Sitio</label>
<input type="text" id="sitio" name="sitio"/>
<span class="mensaje"></span>
</div>


<div class="campo">
<label class="etiqueta" for="concello">O concello</label>
<% include '/listaConcellos.groovy' %>
<span class="mensaje"></span>
</div>

<div class="campo">
<label class="etiqueta" for="parroquia">Parroquia</label>
<input type="text" id="parroquia" name="parroquia"/>
<span class="mensaje"></span>
</div>

<div class="campo">
<label class="etiqueta" for="tipo">Tipo</label>
<% include '/WEB-INF/groovy/listaTiposSitio.groovy' %>
<span class="mensaje"></span>
</div>

<div class="campo">
<label class="etiqueta" for="descricion">Descrición do sitio</label>
<textarea rows="120" cols="90" id="descricion" name="descricion"></textarea>
<span class="mensaje"></span>
</div>




  <div class="controls">
  
       
      <!--<a href="/" id="cancel" class="submit" name="cancel">Cancela</a>-->      
      <input id="submit" class="submit" name="submit" type="submit" 
          value="Crea sitio"/>
      
          
    </div>
    

</fieldset>

</form>
</div>
</div>


</div> <!-- /content -->


<% include "/WEB-INF/includes/pe.gtpl" %>



<script src="js/jquery-1.4.1.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>

<script type="text/javascript">
function creaDatePicker(id) {

    var fecha = ${new Date().format('dd/MM/yyyy')};
    
     jQuery.datepicker.setDefaults(jQuery.extend({showMonthAfterYear: false}));
     jQuery(id).datepicker(
       {
         //showOn: 'focus',
         inline:true,
         changeYear:true,
         showAnim:'fadeIn',
         buttonImage: "/images/date.png",
         buttonImageOnly: true,
         //altField: '#alternate', 
         //altFormat: 'DD, d MM, yy',

         onClose: function(dateText, inst) {
             jQuery(id).change();
             jQuery(id).blur();
         },
         onSelect: function(dateText, inst) {
             jQuery(id).change();
             jQuery(id).blur();
         }

       }
     );

     jQuery(id).datepicker('option',
         jQuery.extend({showMonthAfterYear: false},
         jQuery.datepicker.regional['gl'])
     );

     jQuery(id).datepicker('option', 'changeYear', true);

     jQuery(id).datepicker('option', 'yearRange', '1980:2020');

     //var date = jQuery.datepicker.parseDate('dd/mm/yy',fecha);

     jQuery(id).datepicker('setDate',fecha);

}




</script> 



<script type="text/javascript">
jQuery(function() {

    var validator = jQuery("#formulario").validate({
        rules: {
	        sitio: {
	        required:true,
	        maxlength:50
	        },
            descricion: {
              maxlength:250
            },
            parroquia: {
                maxlength:50
            },
            concello: "required"
        },
        messages: {

        	sitio: {
        	   required:"Este campo é requirido",
        	   maxlength:"Non pode pasar dos 50 caracteres"
            },
        	descricion: {
            	   maxlength:"Non podes pasar dos 250 caracteres"
            },
            parroquia: {
                maxlength:"Non podes pasar dos 50 caracteres"
            },
            concello: "Tes que indicar o concello"
        },
        // the errorPlacement has to take the table layout into account
        errorPlacement: function(error, element) {
            if ( element.is(":radio") )
                error.appendTo( element.parent().next().next() );
            else if ( element.is(":checkbox") )
                error.appendTo ( element.next() );
            else
                //error.appendTo( element.parent().next() );
                error.appendTo( element.next());
        },
        
        // set this class to error-labels to indicate valid fields
        success: function(label) {
            // set &nbsp; as text for IE
            label.html("&nbsp;").addClass("checked");
        }
    });
    
}); 
    
    
</script>   


<% include "/WEB-INF/includes/fin.gtpl" %>


